package com.shanshan.manage.web.controller;

import com.shanshan.manage.common.annotation.Log;
import com.shanshan.manage.common.core.controller.BaseController;
import com.shanshan.manage.common.core.domain.AjaxResult;
import com.shanshan.manage.common.core.page.TableDataInfo;
import com.shanshan.manage.common.enums.BusinessType;
import com.shanshan.manage.common.utils.poi.ExcelUtil;
import com.shanshan.manage.web.domain.ACost;
import com.shanshan.manage.web.service.IACostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 费用Controller
 *
 * @author zhaoShuHeng
 * @date 2023-08-29
 */
@RestController
@RequestMapping("/aCost/aCost")
public class ACostController extends BaseController {
    @Autowired
    private IACostService aCostService;

    /**
     * 查询费用列表
     */
    @PreAuthorize("@ss.hasPermi('aCost:aCost:list')")
    @GetMapping("/list")
    public TableDataInfo list(ACost aCost) {
        startPage();
        List<ACost> list = aCostService.selectACostList(aCost);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('aCost:aCost:list')")
    @GetMapping("/listNoPage")
    public TableDataInfo listNoPage(ACost aCost) {
        List<ACost> list = aCostService.selectACostList(aCost);
        return getDataTable(list);
    }

    /**
     * 导出费用列表
     */
    @PreAuthorize("@ss.hasPermi('aCost:aCost:export')")
    @Log(title = "费用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ACost aCost) {
        List<ACost> list = aCostService.selectACostList(aCost);
        ExcelUtil<ACost> util = new ExcelUtil<ACost>(ACost.class);
        util.exportExcel(response, list, "费用数据");
    }

    /**
     * 获取费用详细信息
     */
    @PreAuthorize("@ss.hasPermi('aCost:aCost:query')")
    @GetMapping(value = "/{costId}")
    public AjaxResult getInfo(@PathVariable("costId") Integer costId) {
        return success(aCostService.selectACostByCostId(costId));
    }

    /**
     * 新增费用
     */
    @PreAuthorize("@ss.hasPermi('aCost:aCost:add')")
    @Log(title = "费用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ACost aCost) {
        return toAjax(aCostService.insertACost(aCost));
    }

    /**
     * 修改费用
     */
    @PreAuthorize("@ss.hasPermi('aCost:aCost:edit')")
    @Log(title = "费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ACost aCost) {
        return toAjax(aCostService.updateACost(aCost));
    }

    /**
     * 删除费用
     */
    @PreAuthorize("@ss.hasPermi('aCost:aCost:remove')")
    @Log(title = "费用", businessType = BusinessType.DELETE)
    @DeleteMapping("/{costIds}")
    public AjaxResult remove(@PathVariable Integer[] costIds) {
        return toAjax(aCostService.deleteACostByCostIds(costIds));
    }
}
